package com.csy.tcshop.cart.config;

import com.csy.tcshop.cart.interceptor.CartInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * springmvc视图映射配置，可以不用在controller层弄空方法只为了返回页面。
 */
@Configuration
public class TcshopWebConfig implements WebMvcConfigurer {

    /**
     * 添加拦截器，光是将拦截器CartInterceptor加入容器中是不行的，得借助WebMvcConfigurer中的addInterceptors方法添加拦截器进springmvc
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CartInterceptor()).addPathPatterns("/**");
    }
}
